<template>
  <div>
    <!-- 把mui-fullscreen这个类去掉不然会盛满全屏 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <!-- :class="['mui-control-item',item.id===0?'mui-active':'']"开始选中全部  -->
          <router-link
            tag="li"
            :to="'/home/photoinfo/'+item.id"
            :class="['mui-control-item', item.id === 0 ? 'mui-active' : '']"
            v-for="(item, index) in category"
            :key="index"
            @tap="getPhotoByCategory(item.id)"
          >
            趁现在
            <!-- {{item.title}} -->
          </router-link>
          <a
            class="mui-control-item"
            href="#item2mobile"
            data-wid="tab-top-subpage-2.html"
          >
            热点
          </a>
          <a
            class="mui-control-item"
            href="#item3mobile"
            data-wid="tab-top-subpage-3.html"
          >
            北京
          </a>
          <a
            class="mui-control-item"
            href="#item4mobile"
            data-wid="tab-top-subpage-4.html"
          >
            社会
          </a>
          <a
            class="mui-control-item"
            href="#item5mobile"
            data-wid="tab-top-subpage-5.html"
          >
            娱乐
          </a>
          <a
            class="mui-control-item"
            href="#item5mobile"
            data-wid="tab-top-subpage-5.html"
          >
            aaa
          </a>
          <a
            class="mui-control-item"
            href="#item5mobile"
            data-wid="tab-top-subpage-5.html"
          >
            ccc
          </a>
          <a
            class="mui-control-item"
            href="#item5mobile"
            data-wid="tab-top-subpage-5.html"
          >
            ddd
          </a>
        </div>
      </div>
    </div>

    <!-- 图片的列表区域 -->
    <ul class="ulcls">
  <li v-for="item in photolist" :key="item.id">
      <!-- v-lazy指定图片的地址 -->
    <img v-lazy="item.img_url">
        <!-- 图片文字 -->
        <div class="info">
            <h1 class="info-title">{{item.title}}</h1>
            <div class="info-content">{{item.zhaiyao}}</div>
        </div>
  </li>
</ul>


  </div>
</template>

<script>
// 导入mui的js文件   因为用到了滚动回弹
import mui from "../../lib/mui/js/mui.js";
export default {
  data() {
    return {
      category: [], //所有的图片分类数据
      photolist: [], // 图片列表
    };
  },
  methods: {
    async getPhotoCategory() {
      // 获取图片的分类数据
      const { data } = await this.$http.get("/api");
      if (data.status === 0) {
        //    手动补全分类的信息
        data.message.unshift({
          title: "全部",
          id: 0,
        });
        this.category = data.message;
      }
    },
    async getPhotoByCategory(id) {
      // 根据图片的分类获取图片的数据
      const { data } = await this.$http.get("/api" + id);
      if (data.status === 0) return (this.photolist = data.message);
    },
  },
  mounted() {
    // 档次钩子函数执行时我们才可以进行控件或插件的初始化工作
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  created() {
    this.getPhotoCategory();
    this.getPhotoByCategory(0);
  },
};
</script>

<style lang="less" scoped>
.mui-slider {
  touch-action: pan-x;
}
.ulcls{
    margin: 0;
    padding: 10px;
}
li{
    text-align: center;
}
img{
    vertical-align: middle;
    width: 100%;
    box-shadow: 0 0 7px gray;
}
img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
li{
    position: relative;
}

.info{
    position: absolute;
    bottom: 0;
    color:#fff;
    background-color: rgba(0, 0, 0, .3);
    max-height: 90px;
    overflow: hidden;
    .info-title{
        font-size: 14px;
    }
    .info-content{
        font-size: 13px;
        text-align: left;
        text-indent: 2em;
    }
}
</style>
